package com.mpyy.handler.systemSetting;

import com.alibaba.fastjson.JSON;
import com.mpyy.dao.ToolInter;
import com.mpyy.pojo.EmployeeInfo;
import com.mpyy.pojo.EmployeeJob;
import com.mpyy.service.systemSetting.StaffServiceInter;
import com.mpyy.tool.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * @PackageName:com.mpyy.handler.systemSetting  员工设置
 * @ClassName:staffSetHandler
 * @Date:2022-03-15:15:19
 * @Author: Tang Neng
 */
@Controller
public class StaffSetHandler {
    @Autowired
    private StaffServiceInter staffServiceInter;
    @Autowired
    private ToolInter toolInter;
    /**
     * 员工信息查询
     * @return
     */
    @RequestMapping("/searchStaffInfo")
    @ResponseBody
    public String searchStaffInfo(){
        List<EmployeeInfo> employeeInfo= staffServiceInter.searchStaffInfo();
//        System.out.println(employeeInfo);
        //创建一个HashMap对象
        HashMap<Object, Object> employeeInfoHashMap = new HashMap<>();
        //对JSON格式进行拼接
        employeeInfoHashMap.put("code",0);
        employeeInfoHashMap.put("msg","");
        employeeInfoHashMap.put("count",employeeInfo.size());
        employeeInfoHashMap.put("data",employeeInfo);
        //装换成JSON格式的字符串，返回到页面
        return JSON.toJSONString(employeeInfoHashMap);
    }

    /***
     * 员工职位查询
     * @return
     */
    @RequestMapping(value = "/searchStaffJobInfo",produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String searchStaffJobInfo(){
        List<EmployeeJob> employeeJobs = staffServiceInter.searchStaffJobInfo();
        //装换成JSON格式的字符串，返回到页面
        return JSON.toJSONString(employeeJobs);
    }

    /**
     * 添加员工信息
     * @return
     */
    @RequestMapping(value = "/updateStaffInfoAdd")
    @ResponseBody
    public int updateStaffInfoAdd(EmployeeInfo employeeInfo){
        //调用自动生成Id方法
        employeeInfo.setEmpId(new Tool().aotomaticId(employeeInfo.getEmpId(), toolInter));
        if(employeeInfo.getEmpStatus() == null){employeeInfo.setEmpStatus(  0);}

        return staffServiceInter.updateStaffInfoAdd(employeeInfo);
    }

    /**
     * 删除员工信息
     * @param empId
     * @return
     */
    @RequestMapping(value = "/updateStaffInfoDelete" , method = RequestMethod.GET)
    @ResponseBody
    public int updateStaffInfoDelete(String empId){
        return staffServiceInter.updateStaffInfoDelete(empId);
    }

    /**
     * 修改员工信息
     * @param employeeInfo
     * @return
     */
    @RequestMapping("/updateStaffInfo")
    @ResponseBody
    public int updateStaffInfo(EmployeeInfo employeeInfo){
        return staffServiceInter.updateStaffInfo(employeeInfo);
    }
}
